package sample.stream.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.Output;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;
import org.springframework.stereotype.Service;
import sample.stream.service.IMessageProvider;

import java.util.UUID;

/**
 * 消息生产者实现类，默认走的是发布-订阅模式
 */
@Service("messageProviderImpl")
@EnableBinding(Source.class) //表明这是一个消息的推送管道（即生产者）
public class MessageProviderImpl implements IMessageProvider {

    @Autowired
    private MessageChannel output; //这里必须命名为output，因为Spring已经默认定义了许多个MessageChannel Bean


    @Override
    public String send() {
        String uuid = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(uuid).build());
        System.out.println("uuid:"+uuid);

        return null;
    }
}
